﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using NLBS.Entity;
using System.Data;

namespace NLBS.Data
{
    public partial class SqlDataProvider : DbProvider
    {
        #region smile

        public override IList<Smile> GetSmile()
        {
            
            DbCommand dbCommand = db.GetSqlStringCommand("select * from blog_Smilies");

            IList<Smile> lists = new List<Smile>();
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                while (dataReader.Read())
                {
                    Smile sm = CommonDataProvider.PopulateSmileFromIDataReader(dataReader);
                    lists.Add(sm);
                }
            }
            return lists;
        }

        public override Smile GetSmileByID(int smID)
        {
            
            DbCommand dbCommand = db.GetSqlStringCommand("select * from blog_Smilies where sm_id=@smID");
            db.AddInParameter(dbCommand, "smID", DbType.Int32, smID);

            Smile sm = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    sm = CommonDataProvider.PopulateSmileFromIDataReader(dataReader);
                }
            }
            return sm;
        }

        public override int InsertSmile(Smile sm)
        {
            
            DbCommand dbCommand = db.GetSqlStringCommand("INSERT INTO blog_Smilies (sm_image,sm_code) values (@image,@code)");
            db.AddInParameter(dbCommand, "image", DbType.String, sm.Image);
            db.AddInParameter(dbCommand, "code", DbType.String, sm.Code);
          return db.ExecuteNonQuery(dbCommand);
        }

        public override void UpdateSmile(Smile sm)
        {
            
            DbCommand dbCommand = db.GetSqlStringCommand("update blog_Smilies set sm_image=@image,sm_code=@code where sm_id=@smID");
            db.AddInParameter(dbCommand, "smID", DbType.String, sm.SmID);
            db.AddInParameter(dbCommand, "image", DbType.String, sm.Image);
            db.AddInParameter(dbCommand, "code", DbType.String, sm.Code);
            db.ExecuteNonQuery(dbCommand);
        }

        public override void DeleteSmile(int smID)
        {
            
            DbCommand dbCommand = db.GetSqlStringCommand("delete blog_Smilies where sm_id=@smID");
            db.AddInParameter(dbCommand, "smID", DbType.Int32, smID);
            db.ExecuteNonQuery(dbCommand);
        }

        #endregion
    }
}
